/*
 * @Author: baiyujing xiaolin.you@ideacome.com
 * @Date: 2024-06-07 14:23:46
 * @LastEditors: baiyujing xiaolin.you@ideacome.com
 * @LastEditTime: 2024-07-05 10:54:32
 * @FilePath: \git_test\sum.js
 * @Description: 
 * 
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
 */
const sum = (a,b) => a+b;
console.log(sum(1,2)); // 3

const sumArr = (arr) => arr.reduce((a,b) => a+b, 0);
console.log(sumArr([1,2,3,4,5])); // 15

const sumArrOdd = (arr) => arr.filter(i => i % 2).reduce((a,b) => a+b, 0);
console.log(sumArrOdd([1,2,3,4,5])); // 9

const sumArrEven = (arr) => arr.filter(i => i % 2 === 0).reduce((a,b) => a+b, 0);
console.log(sumArrEven([1,2,3,4,5])); // 6

const sumArrEven2 = (arr) => arr.reduce((a,b) => a+b, 0) - arr.filter(i => i % 2).reduce((a,b) => a+b, 0);
console.log(sumArrEven2([1,2,3,4,5])); // 6

const sumArrEven3 = (arr) => arr.reduce((a,b) => a+b, 0) - sumArrOdd(arr);  
console.log(sumArrEven3([1,2,3,4,5])); // 6

const sumArrEven4 = (arr) => arr.reduce((a,b) => a+b, 0) - sumArrOdd(arr);
console.log(sumArrEven4([1,2,3,4,5])); // 6
